package com.tensquare.user.dao;

import com.tensquare.user.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口.
 *
 * @author Administrator
 */
public interface UserDao extends JpaRepository<User, String>, JpaSpecificationExecutor<User> {

  /**
   * 根据邮箱获取用户.
   *
   * @param email
   * @return
   */
  User findByEmail(String email);

  /** 更新好友粉丝数 */
  @Modifying
  @Query(value = "update tb_user set fanscount = fanscount + ? where id = ?", nativeQuery = true)
  void updateFanscount(Integer x, String friendid);

  /** 更新用户关注 */
  @Modifying
  @Query(
      value = "update tb_user set followcount = followcount + ? where id = ?",
      nativeQuery = true)
  void updateFollowcount(Integer x, String userid);
}
